void ctl_init()
{
    int i = 0;
    int len = 0;
    len = sizeof(GPO) / sizeof(GPO[0]);
    for (i = 0; i < len; i++)
    {
        pinMode(GPO[i], OUTPUT);
        digitalWrite(GPO[i], 1);
    }
    len = sizeof(GPI) / sizeof(GPI[0]);
    for (i = 0; i < len; i++)
    {
        pinMode(GPI[i], INPUT_PULLUP);
    }
}
void JDctrl()
{
    //0
    if (data_stream_value_rw[0] == 1)
    {
        digitalWrite(GPO[0], 0);
        bumpOn = 1;
    }
    else
    {
        digitalWrite(GPO[0], 1);
        bumpOn = 0;
        curbumpdelay = 0;
    }
    //1
    if (((bumpOn == 1 && data_stream_value_rw[1] == 1) && (W_level[0] == 0 && W_level[1] == 0)) && curbumpdelay >= bumpdelay)
        digitalWrite(GPO[1], 0);
    else
        digitalWrite(GPO[1], 1);
    //2
    if (data_stream_value_rw[2] == 2)
    {
        if (h >= Wave1On[0] && h < Wave1On[1])
        {
            digitalWrite(GPO[2], 0);
        }
        else
        {
            digitalWrite(GPO[2], 1);
        }
    }
    else if (data_stream_value_rw[2] == 1)
    {
        digitalWrite(GPO[2], 0);
    }
    else if (data_stream_value_rw[2] == 0)
    {
        digitalWrite(GPO[2], 1);
    }

    //3
    if (data_stream_value_rw[3] == 2)
    {
        if (h >= Wave2On[0] && h < Wave2On[1])
        {
            digitalWrite(GPO[3], 0);
        }
        else
        {
            digitalWrite(GPO[3], 1);
        }
    }
    else if (data_stream_value_rw[3] == 1)
    {
        digitalWrite(GPO[3], 0);
    }
    else if (data_stream_value_rw[3] == 0)
    {
        digitalWrite(GPO[3], 1);
    }
    //4
    if (data_stream_value_rw[4] > 0)
    {
        digitalWrite(GPO[4], 0);
    }
    else
    {
        digitalWrite(GPO[4], 1);
    }
    //5
    if (data_stream_value_rw[5] == 1)
    {
        digitalWrite(GPO[5], 0);
    }
    else if (data_stream_value_rw[5] == 0)
    {
        digitalWrite(GPO[5], 1);
    }
    //6
    if (data_stream_value_rw[6] == 1)
    {
        digitalWrite(GPO[6], 0);
    }
    else if (data_stream_value_rw[6] == 0)
    {
        digitalWrite(GPO[6], 1);
    }
    //7
    if (data_stream_value_rw[7] == 1)
    {
        digitalWrite(GPO[7], 0);
    }
    else if (data_stream_value_rw[7] == 0)
    {
        digitalWrite(GPO[7], 1);
    }
}
void WRead() //水位传感器
{
    int i = 0;
    for (i = 0; i < 4; i++)
    {
        if (digitalRead(GPI[i]) == 1)
            W_level[i] = 0;
        else
        {
            W_level[i] = 1;
        }
        if (W_level[1] == 1)
            curbumpdelay = 0;
        data_stream_value_r2[i] = W_level[i];
    }
}
void PowerInit()
{
    pidOutput = 0;
    pidOutput2 = 0;
    pidInput = TMP;
    //tell the PID to range between 0 and the full window size
    myQuickPID.SetOutputLimits(0, WindowSize);
    //turn the PID on
    myQuickPID.SetMode(QuickPID::AUTOMATIC);
}
void PowerCtrl()
{
    if (data_stream_value_rw[8] == 1) //o8加热自动
        Setpoint = 21;
    else if (data_stream_value_rw[8] == 0)
    {
        Setpoint = 0;
    }

    if (millis() - windowStartTime >= WindowSize)
    { //time to shift the Relay Window
        pidInput = TMP;
        if (pidInput < Setpoint + 1.0)
            pidOutput2 = pidOutput;
        else
            pidOutput2 = 0;
        windowStartTime += WindowSize;
        myQuickPID.Compute();
    }
    if (((unsigned int)pidOutput2 > minWindow) && ((unsigned int)pidOutput2 > (millis() - windowStartTime)))
        digitalWrite(2, LOW);
    else
        digitalWrite(2, HIGH);
}
